﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Works.model.EF;
using Works.Services;
namespace Works
{
    public partial class FormAdd : Form
    {
        private FinalWorkEntities db = new FinalWorkEntities();
        public FormAdd()
        {
            InitializeComponent();
           
        }



        private void FormAdd_Load(object sender, EventArgs e)
        {
          

            dataGridView1.AllowUserToAddRows = true;
            LoadDataIntoDataGridView();

        }

        private void LoadDataIntoDataGridView()
        {
            using (var db = new FinalWorkEntities())
            {
                var menuData = db.T001menu.ToList();
                dataGridView1.DataSource = new BindingSource(menuData, null);
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var db = new FinalWorkEntities())
            {
                // 创建新的菜单项
                var newMenu = new T001menu
                {
                    Id = int.Parse(textBox3.Text),
                    菜名 = textBox1.Text,
                    价格 = int.Parse(textBox2.Text)
                };

                // 将新菜单项添加到数据库
                db.T001menu.Add(newMenu);
                db.SaveChanges();

                // 刷新数据显示
                LoadDataIntoDataGridView();
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
    
}

